<script>
	var doexesql='__URL__/doexesql';
	var dourlencode='__URL__/dourlencode';
  var dostart='__URL__/dostart';
  var dostop='__URL__/dostop';
  var dogetthrdstat='__URL__/dogetthrdstat';
  var dogetjietu='__URL__/dogetjietu';
  var count_cant=0;
</script>
<!--table部分-->
<div class='col-md-12' style='padding-top:20px'>

    <div class="panel panel-default">
      <div class="panel-heading">控制仪表盘</div>
      <div class="panel-body">
        <div id='operation'>
          <?php if($thrdstat=='true'){ ?>
          <div id='start'><a href='#' onclick='stop()' style='color:#000'><h1><i class='glyphicon glyphicon-pause'></i></h1></a> 当前状态：运行中...</div>
          <?php }else{ ?>
          <div id='stop'><a href='#' onclick='start()' style='color:#000'><h1><i class='glyphicon glyphicon-play'></i></h1></a> 当前状态：停止</div>
          <?php } ?>
        </div>
      </div>
    </div>

    <div class="panel panel-default">
      <div class="panel-heading" id='jietutm'>最新截图时间：{$jietuo['jietutm']}</div>
      <div class="panel-body">
        <img style='width:100%' src="<?php echo C('javahost').$jietuo['jieturelativeroute'] ?>" id='jietuimg'>
      </div>
    </div>
    <script type="text/javascript">
    var immediateitv;
    var itv;
    function start(){
      $.ajax({
          'type': 'GET',
          'url':dostart,
          'async':true,  
          'contentType': 'application/json',
          'data': {},
          'dataType': 'json',
          'success': function(data) {
            console.log("success");
          },
          'error':function() {
            console.log("error");
          }
      });
      immediateitv=setInterval(checkthrdstatimmediate,1000);
      
      // itv=setInterval(checkthrdstat,10000);
      
      
    }
    function checkthrdstatimmediate(){
      $.ajax({
          'type': 'GET',
          'url':dogetthrdstat,
          'async':false,  
          'contentType': 'application/json',
          'data': {},
          'dataType': 'json',
          'success': function(data) {
            var stat=data['stat'];
            if(stat=="true"){
              $('#operation').html("<div id='start'><a href='#' onclick='stop()' style='color:#000'><h1><i class='glyphicon glyphicon-pause'></i></h1></a> 当前状态：运行中...</div>");
            }else{
              $('#operation').html(" <div id='stop'><a href='#' onclick='start()' style='color:#000'><h1><i class='glyphicon glyphicon-play'></i></h1></a> 当前状态：停止</div>");
              
            }
            clearInterval(immediateitv);
            console.log("success");
          },
          'error':function() {
            console.log("error");
          }
      });

      
    }
    function checkthrdstat(){
      $.ajax({
          'type': 'GET',
          'url':dogetthrdstat,
          'async':false,  
          'contentType': 'application/json',
          'data': {},
          'dataType': 'json',
          'success': function(data) {
            var stat=data['stat'];
            if(stat=="true"){
              count_cant=0;
              $('#operation').html("<div id='start'><a href='#' onclick='stop()' style='color:#000'><h1><i class='glyphicon glyphicon-pause'></i></h1></a> 当前状态：运行中...</div>");
            }else{
              count_cant++;
              if(count_cant<4){return;}
              $('#operation').html(" <div id='stop'><a href='#' onclick='start()' style='color:#000'><h1><i class='glyphicon glyphicon-play'></i></h1></a> 当前状态：停止</div>");
              // clearInterval(itv);
            }

            console.log("success");
          },
          'error':function() {
            console.log("error");
          }
      });

      $.ajax({
          'type': 'GET',
          'url':dogetjietu,
          'async':false,  
          'contentType': 'application/json',
          'data': {},
          'dataType': 'json',
          'success': function(data) {
            var jietuo=data['jietuo'];
            
            $('#jietutm').html("最新截图时间："+jietuo['jietutm']);
            var imgsrc="<?php echo C('javahost') ?>"+jietuo['jieturelativeroute'];
            if($('#jietuimg').attr('src')==""){$('#jietuimg').attr('src',imgsrc);}else{$('#jietuimg').attr('src',"");}return;
            $('#jietuimg').attr('src',"");
            $('#jietuimg').attr('src',imgsrc);
            console.log("success");
          },
          'error':function() {
            console.log("error");
          }
      });

    }
    function stop(){
      $.ajax({
          'type': 'GET',
          'url':dostop,
          'async':false,  
          'contentType': 'application/json',
          'data': {},
          'dataType': 'json',
          'success': function(data) {
            immediateitv=setInterval(checkthrdstatimmediate,100);
            console.log("success");
          },
          'error':function() {
            console.log("error");
          }
      });
     
      
      
      
    }

    itv=setInterval(checkthrdstat,10000);

    </script>
	
</div>




